package org.lixue.game.server.handler.websocket;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class WebSocketMessageHandler extends SimpleChannelInboundHandler<WebSocketFrame> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame msg) throws Exception {
        if (msg instanceof TextWebSocketFrame) {
            log.info("Received text : {}", ((TextWebSocketFrame) msg).text());
            // 分发事件处理
            ctx.writeAndFlush("hello client");
        } else {
            throw new UnsupportedOperationException("Invalid websocket frame received");
        }
    }

}
